package com.lans.SortAlgorithm;

import java.util.Arrays;

/*
 * @author: lans
 * @date: 2025/1/10
 * @name: 刘宇
 * 冒泡排序
 */
public class BubblingSort {
    public static void main(String[] args) {
        int[] arrays = new int[]{3,1,3,5,7,5,9,8};
        int[] arrays1 = sort(arrays);
        System.out.println(Arrays.toString(arrays1));
    }
    public static int[] sort(int[] arrays){
        for(int i=0;i<arrays.length-1;i++){
            boolean flag = false;
            for(int j = 0;j<arrays.length-i-1;j++){
                if(arrays[j]>arrays[j+1]){
                    int temp = arrays[j];
                    arrays[j] = arrays[j+1];
                    arrays[j+1] = temp;
                    flag=true;
                }
            }
            if(!flag){
                break;
            }
        }
        return arrays;
    }
}
